//
//  IWTabBar.m
//  SINA
//
//  Created by 王相超 on 16/3/28.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

#import "IWTabBar.h"

@interface IWTabBar()

@property(weak,nonatomic)UIButton *plusBtn;

@end

@implementation IWTabBar
@dynamic delegate;

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
      //  self.backgroundColor = [UIColor whiteColor];
        
        UIButton *button = [[UIButton alloc] init];
        
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        button.size = button.currentBackgroundImage.size;
        
        [button addTarget:self action:@selector(plusButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:button];
        
        self.plusBtn = button;
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.plusBtn.centerX = self.width / 2;
    self.plusBtn.centerY = self.height / 2;
    
    NSInteger count = self.subviews.count;
    
    CGFloat w = self.width / 5;
    
    NSInteger index = 0;
    
    for (int i = 0; i < count; i++) {
        
        UIView *childView = self.subviews[i];
        
        if ([childView isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            
            childView.width = w;
            
            childView.x = w * index;
            
            index ++;
            
            if (index==2) {
                index++;
            }
            
        }
        
    }
  
}
//
//
//-(void)plusButtonClick:(UIButton *)sender {
//    
//    if ([self.delegate respondsToSelector:@selector(taBar:didSelectedButton:)]) {
//        
//        [self.delegate taBar:self didSelectedButton:sender];
//    }
//    
//    
//}

@end
